package com.dsg.workflow;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dsg.entity.apply.DsgApplyBill;
import com.dsg.entity.apply.DsgApplyCard;
import com.dsg.entity.apply.DsgApplyStatus;
import com.dsg.entity.approve.DsgApproveCase;
import com.dsg.service.apply.IDsgApplyBillService;
import com.dsg.service.apply.IDsgApplyCardService;
import com.dsg.service.apply.IDsgApplyStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 停咭
 */
@Service
public class WorkflowService10 extends AbstractWorkflowService {
    @Autowired
    IDsgApplyStatusService statusService;
    @Autowired
    IDsgApplyCardService cardService;
    @Autowired
    IDsgApplyBillService billService;

    @Override
    public void approveFillBack(DsgApproveCase approveCase) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("APP_NO", approveCase.getAppNo());
        DsgApplyBill bill = billService.getOne(wrapper);
        if (bill.getApproveStatus() == DsgApplyBill.APPROVE_STATUS_AGREE)
            return;

        wrapper = new QueryWrapper();
        wrapper.eq("APP_NO", approveCase.getAppNo());
        DsgApplyStatus status = statusService.getOne(wrapper);

        LambdaUpdateWrapper<DsgApplyCard> updateWrapper = new LambdaUpdateWrapper();
        updateWrapper.eq(DsgApplyCard::getOid, status.getCardId());
        DsgApplyCard card = new DsgApplyCard();
        card.setCardStatus(DsgApplyCard.CARD_STATUS_7);
        cardService.update(card, updateWrapper);

        bill.setAppStatus(DsgApplyBill.APP_STATUS_4);
        billService.updateById(bill);
    }
}
